package leetCode;

import org.junit.Test;

/**
 * 二分查找
 *
 * @author 司松坡
 * @createTime 2023年04月03日
 */
public class LeetCode704 {
    public int search(int[] nums, int target) {
        int mid;
        int max = nums.length - 1;
        int min = 0;
        while (max >= min) {
            mid = min + (max - min ) / 2;
            if (nums[mid] == target) {
                return mid;
            }
            if (nums[mid] > target) {
                max = mid -1;
            } else {
                min = mid +1;
            }
        }
        return -1;
    }

    @Test
    public void test() {
        System.out.println(search(new int[]{5}, 5));
    }
}
